package workexp.alg.question;

import org.junit.Test;

public class SearchInsert {

    public int searchInsert(int[] nums, int target) {
        int low=0;
        int high=nums.length;
        while (low<=high){
            int mid = (high-low)/2+low;
            if(nums[mid]==target){
                return mid;
            }else if(nums[mid]<target){
                low=mid+1;
            }else if(nums[mid]>target){
                high=mid-1;
            }
        }
        return low;
    }

    @Test
    public void test(){
        int[] nums = {1,2,4,5,6,7};
        int target = 3;
        int s = searchInsert(nums,target);
        System.out.println(s);
    }
}
